/**
 * This is a header for simple multiplatform
 * Dynamic library loads.
 *
 * @copyright 2008 Kirill Gavrilov
 */

#include "loadLibrary.h"

/**
 * Function call system function to return library handle.
 * Returns NULL if not found.
 * @param destination (const char* ) - library destination;
 * @return HMODULE (means void* ) - handle of library.
 */
    HMODULE DLibLoad(const char* destination) {
#if (defined(_WIN32) || defined(__WIN32__))
        return LoadLibrary(destination);
#else
        return dlopen(destination, RTLD_NOW);
#endif
    }

/**
 * Function call system function to return function address in library.
 * Returns NULL if not found.
 * @param libHandle (HMODULE = void* ) - library handle;
 * @param fname (const char* ) - function name;
 * @return void* - pointer to function in library.
 */
    void* DLibGetFunction(HMODULE libHandle, const char* fname) {
#if (defined(_WIN32) || defined(__WIN32__))
        return (HMODULE )GetProcAddress(libHandle, fname);
#else
        return dlsym(libHandle, fname);
#endif
    }

/**
 * Function call system function to release library.
 * (free memory).
 * @param libHandle (HMODULE = void* ) - library handle;
 */
    void DLibFree(HMODULE libHandle) {
#if (defined(_WIN32) || defined(__WIN32__))
        FreeLibrary(libHandle);
#else
        dlclose(libHandle);
#endif
    }



